package com.tuzhi.util;

import com.tuzhi.common.constants.security.AuthConstant;
import com.tuzhi.common.domain.LoginUserBO;
import org.apache.commons.collections.CollectionUtils;

/**
 * 从 tuzhi-auth-user AuthBaseCotroller 移出来的方法，暂放在这
 */
public class AuthUtil {
    public static boolean curLoginContainsRole(LoginUserBO curLogin, String roleName) {
        if (curLogin == null) {
            return false;
        }
        if (CollectionUtils.isNotEmpty(curLogin.getRoles())) {
            return curLogin.getRoles().contains(roleName);

        }
        return false;
    }

    public static boolean isContainEngineerRole(LoginUserBO curLogin) {
        return curLoginContainsRole(curLogin, AuthConstant.ROLE_ENGINEER);
    }

    public static boolean isContainProcessingQuoterRole(LoginUserBO curLogin) {
        return curLoginContainsRole(curLogin, AuthConstant.ROLE_PROCESSINGQUOTER);
    }

    public static boolean isContainManagerRole(LoginUserBO curLogin) {
        return curLoginContainsRole(curLogin, AuthConstant.ROLE_MANAGER);
    }
}
